﻿using System.Data.Common;
using System.Data.SqlClient;
using XStudio.XCRF.Data.Configurations;
using XStudio.XCRF.Utilities.Base64Encryption;
using System;

namespace XStudio.XCRF.Data
{
    /// <summary>
    /// XCRF数据库访问连接
    /// </summary>
    public class XCRFConnection
    {
        #region 核心

        private DbConnection _DbConnection;
        /// <summary>
        /// 数据库连接对象
        /// </summary>
        public DbConnection DbConnection
        {
            get { return _DbConnection; }
            set { _DbConnection = value; }
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="conStr">连接字符串</param>
        public XCRFConnection(string conStr = null)
        {
            if (string.IsNullOrWhiteSpace(conStr))
                conStr = DefaultConnectionString;
            DbConnection = new SqlConnection(conStr);
        }

        #endregion 核心

        #region 扩展

        private static string _DefaultConnectionString = null;
        /// <summary>
        /// 默认XCRF数据库链接字符串
        /// </summary>
        public static string DefaultConnectionString
        {
            get
            {
                if (_DefaultConnectionString == null)
                    _DefaultConnectionString = XCRFConfig.Default.ConectionCode.Base64Decode();
                return _DefaultConnectionString;
            }
        }

        #endregion 扩展
    }
}
